package com.company.cloud.oss.modules.app.utils;

import org.springframework.util.StringUtils;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;

public class FileNameUtils {

	

	private static final String EXTENSION_CHARACTER = ".";

	/**
	 * 通过文件名获取扩展名
	 * @param fileName
	 * @return
	 */
	public static String getExtension(String fileName) {
		String extension = "";
		if(StringUtils.hasText(fileName) && fileName.contains(EXTENSION_CHARACTER)) {
			extension = fileName.substring(fileName.lastIndexOf(EXTENSION_CHARACTER)+1);
		}else {
			extension=fileName;
		}
		return extension;
	}
	
	public static String getFileName(String fileNo,String fileFormat) {
		return fileNo+EXTENSION_CHARACTER+fileFormat;
	}
	
	public static String getFileName(String fileName) {
		return IdUtil.simpleUUID()+EXTENSION_CHARACTER+getExtension(fileName);
	}
	
	public static String getImgNo() {
		return StrUtil.format("FILE_{}", IdUtil.getSnowflake(6, 1).nextIdStr());
	}
	
	
	
}
